package com.sg.fileService.service.impl;

import org.springframework.stereotype.Service;

import com.sg.common.exception.BaseBusinessException;
import com.sg.fileService.common.FileUploadException;
import com.sg.fileService.entity.FileTypeConfig;
import com.sg.fileService.model.EnumSize;
import com.sg.fileService.util.MP4AVEncoder;
import com.sg.fileService.util.PNGAVEncoder;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class VideoUploadServiceImpl extends BaseFileUploadServiceImpl {
	@Override
	protected void doEncoder(String sourcePath, FileTypeConfig fileConfig)  throws BaseBusinessException{
		//如果需要进行视频转换
		if(fileConfig.getEncodeAble()){
			MP4AVEncoder encoder = new MP4AVEncoder();
			PNGAVEncoder pngEncoder = new PNGAVEncoder();
			try{
				pngEncoder.encoderVideo(sourcePath, EnumSize.BREVIARY_IMG);
				//生成小中大三种视屏分辨率的保存路径,进行转码
				encoder.encoderVideo(sourcePath,EnumSize.MINI_SIZE);
				encoder.encoderVideo(sourcePath,EnumSize.MIDDLE_SIZE);
				encoder.encoderVideo(sourcePath,EnumSize.BIG_SIZE);
			}catch(Exception e){
				log.error("-->视屏:{}处理失败:{}",sourcePath,e.getMessage());
				throw new BaseBusinessException("文件转码失败"); 
			}
		}
		
	}

}
